<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');

class Cache {
	private $CI;
	private $_cache_pwd;
	
	function Cache() {
		$this->CI = &get_instance();
		$this->CI->load->helper('file');
		$this->_cache_pwd = $this->CI->config->item('CachePwd');
	}
	
	function Store($cache_key, $cache_data) {
		$fpath = $_SERVER['DOCUMENT_ROOT'] . '/cache/' . $cache_key . '.' . $this->_cache_pwd;
		return write_file($fpath, $cache_data);
	}
	
	function Load($cache_key) {
		$fpath = $_SERVER['DOCUMENT_ROOT'] . '/cache/' . $cache_key . '.' . $this->_cache_pwd;
		return read_file($fpath);
	}
	
	function Remove($cache_key) {
		$fpath = $_SERVER['DOCUMENT_ROOT'] . '/cache/' . $cache_key . '.' . $this->_cache_pwd;
		if(file_exists($fpath)) {
			unlink($fpath);
		}
	}
	
	function RemoveAll() {
		$dpath = $_SERVER['DOCUMENT_ROOT'] . '/cache';
		delete_files($dpath);
	}
}
?>